<template>
  <div class="trainingClass">
    <div class="JADP-common-layout-main JADP-flex-main">
      <JADP-table v-loading="listLoading" :data="list" @sort-change="sortChange">
        <el-table-column prop="classno" label="班级编号" align="left" />
        <el-table-column prop="classname" label="班级名称" align="left">
          <template #default="{ row }">
            <ShowAllText :row="row.classname" :num="8" />
          </template>
        </el-table-column>

        <el-table-column prop="categorytype" label="行业类型" align="left" width="135">
          <template slot-scope="scope">
            <!-- {{ scope.row.categorytype }} -->
            {{ getDict("hangye", scope.row.categorytype) }}
          </template>
        </el-table-column>
        <el-table-column label="培训类别" prop="trainType" algin="left">
          <template slot-scope="scope">
            <!-- {{ getDict("pxlb", scope.row.trainType) }} -->
            {{ scope.row.trainType }}
          </template>
        </el-table-column>

        <el-table-column prop="traindateStart" label="培训开始时间" align="left" width="135" />

        <el-table-column prop="traindateEnd" label="培训结束时间" align="left" width="135" />

        <el-table-column label="培训方式" prop="trainMode" algin="left">
          <template slot-scope="scope">
            {{ scope.row.trainMode }}
            <!-- {{ getDict("bjpxfs", scope.row.trainMode) }} -->
          </template>
        </el-table-column>

        <el-table-column prop="hours" label="学时" align="left">
        </el-table-column>
      </JADP-table>

      <pagination :total="total" :page.sync="listQuery.currentPage" :limit.sync="listQuery.pageSize"
        @pagination="initData" />
    </div>
  </div>
</template>
<script>
import request from "@/utils/request";
export default {
  name: "trainingClass",
  inject: ["stuid"],
  emits: ['update-value'],
  data() {
    return {
      list: [],
      listLoading: false,
      total: 0,
      listQuery: {
        currentPage: 1,
        pageSize: 20,
        sort: "desc",
        sidx: ""
      },
      isEvidenceCollection: false,
    };
  },
  created() {
    this.$nextTick(() => {
      this.initData();
    });
  },
  methods: {
    initData() {
      this.listLoading = true;
      let query_ = {
        ...this.listQuery,
        archivesid: this.stuid.id,
        organizeId: this.$store.getters.organizeId
      };
      request({
        url: `/api/xy_da_class_archives/Xy_da_class_archives`,
        method: "get",
        data: query_
      }).then(res => {
        this.list = res.data.list;        
        if (this.list.some(item => item.trainType == "主要负责人和安全管理人员")) {
          this.isEvidenceCollection = true;
        }
        this.$emit('update-value', this.isEvidenceCollection);
        this.total = res.data.pagination.total;
        this.listLoading = false;
      });
    },

    sortChange({ column, prop, order }) {
      this.listQuery.sort = order == "ascending" ? "asc" : "desc";
      this.listQuery.sidx = !order ? "" : prop;
      this.initData();
    }
  }
};
</script>
<style scoped lang="scss">
.trainingClass {
  padding: 10px 20px;
  height: 100%;

  .JADP-common-layout-main {
    height: 100%;
  }
}
</style>
